package 集合.setExamples;

import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Random;
import java.util.TreeSet;

public class SetOfInteger {
	public static void main(String[] args) {
		//testHashSet();
		testTreeSet();
	}

	private static void testTreeSet() {
		Random random = getRandom();
		TreeSet<Integer> set = new TreeSet<Integer>();
		for (int i = 0; i < 10000; i++) {
			int e = random.nextInt(30);
			set.add(e);
		}
		System.out.println(set);
	}

	@NotNull
	private static Random getRandom() {
		return new Random(47);
	}

	private static void testHashSet() {
		Random random = getRandom();
		HashSet<Integer> hashSet = new HashSet<>();
		for (int i = 0; i < 10000; i++) {
			int e = random.nextInt(30);

			hashSet.add(e);
		}
		// 看到 有10000个，但是其实，只有30以内的几个。
		// 按理说 hashSet 是无需的
		System.out.println(hashSet);
	}
}
